#include<bits/stdc++.h>
using namespace std;
class BrowserHistory {
public:
    vector<string> ret;
    int idx=0;
    BrowserHistory(string homepage) {
        ret.push_back(homepage);
    }
    
    void visit(string url) {
        int n=ret.size();
        while(n-1!=idx)
        {
            n--;
            ret.pop_back();
        }
        idx++;
        ret.push_back(url);
    }
    
    string back(int steps) {
        int m=max(0,idx-steps);
        idx=m;
        return ret[idx];
    }
    
    string forward(int steps) {
        int n=ret.size()-1;
        int m=min(n,idx+steps);
        idx=m;
        return ret[idx];
    }
};

/**
 * Your BrowserHistory object will be instantiated and called as such:
 * BrowserHistory* obj = new BrowserHistory(homepage);
 * obj->visit(url);
 * string param_2 = obj->back(steps);
 * string param_3 = obj->forward(steps);
 */